<template>
  <div class="inventory-in">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>入库管理</span>
          <el-button type="primary">新增入库单</el-button>
        </div>
      </template>

      <!-- 搜索区域 -->
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="入库单号">
          <el-input v-model="searchForm.orderNo" placeholder="请输入入库单号" />
        </el-form-item>
        <el-form-item label="入库状态">
          <el-select v-model="searchForm.status" placeholder="请选择状态">
            <el-option label="待入库" value="pending" />
            <el-option label="已入库" value="completed" />
            <el-option label="已取消" value="cancelled" />
          </el-select>
        </el-form-item>
        <el-form-item label="入库日期">
          <el-date-picker
            v-model="searchForm.date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格区域 -->
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column prop="orderNo" label="入库单号" width="180" />
        <el-table-column prop="date" label="入库日期" width="120" />
        <el-table-column prop="supplier" label="供应商" />
        <el-table-column prop="amount" label="入库金额" width="120">
          <template #default="scope">
            ¥{{ scope.row.amount }}
          </template>
        </el-table-column>
        <el-table-column prop="operator" label="操作人" width="120" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="scope.row.status === 'completed' ? 'success' : scope.row.status === 'pending' ? 'warning' : 'info'">
              {{ scope.row.status === 'completed' ? '已入库' : scope.row.status === 'pending' ? '待入库' : '已取消' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="scope">
            <el-button type="primary" link>查看</el-button>
            <el-button type="primary" link>入库</el-button>
            <el-button type="danger" link>取消</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const searchForm = reactive({
  orderNo: '',
  status: '',
  date: []
})

const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

const tableData = ref([
  {
    orderNo: 'IN20240317001',
    date: '2024-03-17',
    supplier: '供应商A',
    amount: 1999.99,
    operator: '张三',
    status: 'pending'
  },
  {
    orderNo: 'IN20240317002',
    date: '2024-03-17',
    supplier: '供应商B',
    amount: 2999.99,
    operator: '李四',
    status: 'completed'
  },
  {
    orderNo: 'IN20240317003',
    date: '2024-03-17',
    supplier: '供应商C',
    amount: 3999.99,
    operator: '王五',
    status: 'cancelled'
  }
])

const handleSearch = () => {
  console.log('搜索条件：', searchForm)
}

const resetSearch = () => {
  searchForm.orderNo = ''
  searchForm.status = ''
  searchForm.date = []
}
</script>

<style scoped>
.inventory-in {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.search-form {
  margin-bottom: 20px;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style> 